package com.hualan.servlet;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hualan.bean.PanghuCommunity;
import com.hualan.dao.CommunityDao;
import com.hualan.dao.CommunityDaoImpl;
import com.hualan.dao.GeneralResult;
import com.hualan.dao.HttpUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/community/updatecommunity")
public class CommunityUpdateDateServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        CommunityDao communityDao = new CommunityDaoImpl();
        String communityName = req.getParameter("communityName");
        String communityProvince = req.getParameter("communityProvince");
        String communityCity = req.getParameter(" communityCity");
        String communityDistrict = req.getParameter("communityDistrict");
        String communityCoordinates= req.getParameter("communityCoordinates");
        int communityId = Integer.parseInt(req.getParameter("communityId")) ;
       String communityAddress = req.getParameter("communityAddress");
        String communityLatitude = req.getParameter("communityLatitude");
        String communityLongitude = req.getParameter("communityLongitude");


        PanghuCommunity community = new PanghuCommunity(communityName,communityProvince,communityDistrict,communityCoordinates,communityAddress,communityLatitude,communityLongitude,communityId);
        int num = communityDao.update(community);
        Map<String, Object> map = new HashMap<>();
        if (num > 0){
            map.put("code",200);
        }else {
            map.put("code",300);
        }

        resp.getWriter().write(JSON.toJSONString(map));
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
}

